package controllers

import (
	"github.com/astaxie/beego"
	"analysis-ss/dt"
)

type CenterController struct {
	beego.Controller
}

func (c *CenterController) URLMapping() {
	c.Mapping("GetCenters", c.GetCenters)
}

// @Title 获取中心的课程信息
// @Description 根据中心编号获取中心对应的课程信息
// @Param	cid		query	int	false	"中心编号"
// @Param	start		query	int	true	"起始记录号"
// @Param	length		query	int	true	"每页记录数"
// @Success 200 {object} models.DataTable
// @router / [get]
func (c *CenterController) GetCenters() {

	// 获得条件参数
	centerId := c.GetString("cid")
	start, err := c.GetInt("start")
	if err != nil {
		start = 0
	}
	length, err := c.GetInt("length")
	if err != nil {
		length = 10
	}

	centers := new(dt.Centers)
	err = centers.GetTableInfo(start, length, centerId)
	// TODO 异常处理

	c.Data["json"] = centers
	c.ServeJSON()
}
